package wiModel;

import java.util.ArrayList;
import wiBase.WiException;
import wiBase.WiObject;
import wiBase.baseInterface.OnAdapterListener;
import wiBase.baseObject.Event;
import wiBase.baseObject.Node;
import wiBase.baseObject.Packet;

/**
 * adapter of WiModel.
 *
 */
public class WiModelAdapter implements OnAdapterListener {

    private WiModelManager _modelManager = null;

    public WiModelAdapter() {
	init();
    }

    private void init() {
	_modelManager = WiModelManager.getInstance();
    }

    /**
     * @return path of trace file
     */
    @Override
    public String getFileTrace() {
	return _modelManager.getNameFileTrace();
    }

    /**
     * return path of configuration file
     */
    @Override
    public String getFileConfig() {
	return _modelManager.getNameFileConfig();
    }

    /**
     * return array list of nodes
     */
    @Override
    public ArrayList<WiObject> getListNodes() {
	return _modelManager.getListNodes();
    }

    /**
     * return array list of packets
     */
    @Override
    public ArrayList<WiObject> getListPackets() {
	return _modelManager.getListPackets();
    }

    /**
     * return array list of events
     */
    @Override
    public ArrayList<WiObject> getListEvents() {
	return _modelManager.getListEvents();
    }

    /**
     * @return sum of time parse file trace
     */
    @SuppressWarnings("static-access")
    @Override
    public long getMilliTimeParse() {
	return _modelManager.getFinishTimeParse() - _modelManager.getStartTimeParse();
    }

    /**
     * return duration of simulation. (second)
     */
    @Override
    public double getDurationSimulation() {
	return _modelManager.getDurationSimulation();
    }

    /**
     * return height of simulation.
     */
    @Override
    public double getLength() {
	return _modelManager.getLength();
    }

    /**
     * return width of simulation.
     */
    @Override
    public double getWidth() {
	return _modelManager.getWidth();
    }
    
    @Override
    public Node getNodeById(int id) {
	return _modelManager.getNode(id);
    }

    @Override
    public void setTraceFile(String traceFile) {
	_modelManager.setTraceFile(traceFile);
    }

    @Override
    public void parse() throws WiException {
	_modelManager.parse();
    }

    public void parse(boolean debug, boolean useNative) throws WiException {
	_modelManager.parse(debug, useNative);
    }
    
    @Override
    public void cancelParse() throws WiException {
	_modelManager.cancelParse();
    }

    @Override
    public boolean isParsed() {
	return _modelManager.isParsed();
    }
    /**
     * set path of config file
     * @param cfgFile path config file.
     */
    @Override
    public void setConfFile(String cfgFile) {
	_modelManager.setConfigFile(cfgFile);
    }

    public Packet getPacketById(int idPacket) {
	return _modelManager.getPacket(idPacket);
    }

    public Event getEventById(int idEvent) {
	return _modelManager.getEvent(idEvent);
    }

    public Node getNodeOrgById(int id) {
	return _modelManager.getNodeOrg(id);
    }
    /**
     * set init state after trace file.
     */
    public void copyData() {
	_modelManager.reset();
    }
    /**
     * reset data to new parse traceFile
     */
    public void clear() {
	WiModelManager.clearData();
    }
}
